<style>
    .tabliv {
        display: none;
    }

    .tabliv > table th, .tabliv > table td {
        padding: 8px;
        border-bottom: 1px solid #555;
    }
    .list-inline {
        padding-left: 0;
        list-style: none;
        margin-left: -5px;
    }
    .list-inline > li {
        display: inline-block;
        padding-left: 5px;
        padding-right: 5px;
    }
</style>

<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">sku实时库存</h3></div>
            <div class="panel-body">
                <form action="__URL__/sku_real_inventory" method="post" id="form_search">


                    <div class="col-sm-12 col-md-4  add-space">
                        <div class="input-group input-group-md">
                            <span class="input-group-addon">所属公司主体</span>
                            <select name="enterprise_dominant" id="enterprise_dominant" class="form-control">
                                <option value="">--请选择--</option>
                                <volist name="enterprise_dominant" id="val" key="num">
                                    <option value="{$num}">{$val}</option>
                                </volist>
                            </select>
                        </div>
                    </div>

                    <div class="col-sm-12 col-md-3  add-space">
                        <div class="input-group input-group-md">
                            <span class="input-group-addon">是否退税</span>
                            <select class="form-control" name="export_tax_rebate"
                                    data-name-group="common">
                                <option value="">-- 请选择 --</option>
                                <option value="1">出口退税</option>
                                <option value="-1">非出口退税</option>
                            </select>
                        </div>
                    </div>

                    <div class="col-sm-12 col-md-3  add-space">
                        <div class="input-group input-group-md">
                            <span class="input-group-addon">站点</span>
                            <select class="form-control" name="site_id"
                                    data-name-group="common" style="width:180px;">
                                <option value="">-- 请选择 --</option>
                                <volist name="sites" id="value">
                                    <option value="{$key}">{$value}</option>
                                </volist>
                            </select>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-sm-12 col-md-4 add-space">
                        <div class="input-group input-group-md">
                            <span class="input-group-addon">SKU</span>
                            <textarea name="sku" id="sku" class="form-control" cols="5" rows="3" placeholder="例如：
A301
A401"><?php echo trim($_POST['sku']);?></textarea>
                        </div>
                    </div>
                    <div class="col-sm-12 col-md-4  add-space">
                        <input class="btn btn-primary" type="submit" value="查询">
                        <input class="btn btn-primary" type="button" onclick="reset()" value="重置">
                        <input class="btn btn-success" type="button" value="下载" id="download">
                        <span>&nbsp;&nbsp;数据不超过2000行</span>
                    </div>
                </form>
            </div>
            <div class="clearfix"></div>
            <hr>

            <table class="table table-bordered" id="table_content"
                   style="border-collapse:collapse;width: 98%;margin-left: 10px;">
                <thead>
                <tr>
                    <th>序号</th>
                    <th></th>
                    <th>sku</th>
                    <th>采购名称</th>
                    <th>sku实时库存</th>
                    <th>入库单可用库存</th>
                    <th>sku实际可用库存</th>
                    <th>占用库存</th>
                    <th>是否退税</th>
                    <th>站点</th>
                    <th>公司主体</th>
                </tr>
                </thead>
                <tbody id="div_content">
                <volist name="data" id="val" key="num">
                    <tr>
                        <td>{$num}</td>
                        <td id="tr{$val.id}" class="detailtr"><!--data-toggle="modal" data-target="btn_ck"
                            onclick="write_detail($str)"--><font color="#008b8b" style="cursor:pointer; ">展开</font></td>
                        <td>{$val.sku}</td>
                        <td>{$val.sku_name}</td>
                        <td>
                            <if condition="$val['quantity'] neq $val['avaliable_quantity']">
                                <font color="red">{$val.quantity}</font>
                                <else/>
                                {$val.quantity}
                            </if>
                        </td>
                        <td>
                            <if condition="$val['quantity'] neq $val['avaliable_quantity']">
                                <font color="red">{$val.avaliable_quantity}</font>
                                <else/>
                                {$val.avaliable_quantity}
                            </if>
                        </td>
                        <td><?php echo $val['avaliable_quantity']-$val['occupy_quantity']?></td>
                        <td>{$val.occupy_quantity}</td>
                        <td>{$val.export_tax_rebate}</td>
                        <td>{$val.site_id}</td>
                        <td>{$val.enterprise_dominant}</td>
                    </tr>
                    <tr>
                        <td id="tr{$val.id}s" class="tabliv" colspan="9">
                            <div class="alert alert-info" role="alert">
                                <span>前面为储位,后为储位对应的数量</span>
                                <ul class="list-inline">
                                    <volist name="val.details" id="vo">
                                    <li>{$vo.storage_position}：{$vo.all_available_quantity}&nbsp;&nbsp;&nbsp;&nbsp;</li>
                                    </volist>
                                </ul>
                            </div>
                        </td>
                    </tr>
                </volist>
                </tbody>
            </table>
            <div class="clearfix clear"></div>
            <div class="row" style="margin-top: 20px;padding-bottom: 15px; width: 98%;margin-left: 10px;">
                <div class="col-md-6 pull-left">
                    <label>每页 20 条记录
                        显示 1 到 20 项，共 {$count}项</label>
                </div>
                <div class="col-md-6">
                    <div class="page pull-right" style="padding: 0;margin: 0">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>


<!-- 详情 -->
<div class="modal fade btn_ck">
    <div class="modal-dialog modal-lg">

        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">关闭</span></button>
                <h4 class="modal-title">明细</h4>
            </div>
            <div class="modal-body">
                <table>
                    <thead>
                    <tr>
                        <th width="19%">储位</th>
                        <th width="2%">数量</th>
                    </tr>
                    </thead>
                    <tbody id="detail">

                    </tbody>
                </table>
            </div>

        </div>
    </div>
</div>
<script>
    $(function () {
        $("select[name='export_tax_rebate']").val("<?php echo $_POST['export_tax_rebate']?>");
        $("select[name='enterprise_dominant']").val("<?php  echo $_POST['enterprise_dominant'];?>");
        $("select[name='site_id']").val("<?php  echo $_POST['site_id'];?>");
    });

    /**
     * 重置
     * */
    function reset() {
        $('#form_search').find('input').val('');
        $('#form_search').find('select').val('');
        $('#sku').val('');
    }
    /**
     * 下载
     */
    $("#download").click(function () {
        var sku = $("#sku").val();
        sku=sku.replace(/\r\n/g,",");
        sku=sku.replace(/\n/g,",");
        var enterprise_dominant = $("select[name='enterprise_dominant']").val();
        var export_tax_debate = $("select[name='export_tax_debate']").val();
        var site_id = $("select[name='site_id']").val();
        post('__URL__/sku_real_inventory_download', {'sku':sku,'enterprise_dominant':enterprise_dominant,
            'export_tax_debate':export_tax_debate,'site_id':site_id});
    });

    function post(URL, PARAMS) {
        var temp = document.createElement("form");
        temp.action = URL;
        temp.method = "post";
        temp.style.display = "none";
        for (var x in PARAMS) {
            var opt = document.createElement("textarea");
            opt.name = x;
            opt.value = PARAMS[x];
            // alert(opt.name)
            temp.appendChild(opt);
        }
        document.body.appendChild(temp);
        temp.submit();
        return temp;
    }

    /**
     * 展开关闭
     */
    $(".detailtr").click(function () {
        var trid = $(this).attr("id");
        $("#" + trid + "s").toggle();
        if ($(this).text() == '展开') {
            $(this).text('关闭');
            $(this).css('color', 'red')
        } else {
            $(this).text('展开');
            $(this).css('color', '#008b8b')
        }
    });

    /*
    分页
     */
    $('.page a').click(function(){
        var tmpHref = $(this).attr('href');
        tmpHref = tmpHref.replace(/\/selCon\//,"");
        $("#form_search").attr("action", tmpHref);
        $("#form_search").submit();
        return false;
    });

    $("#selecting").click(function(){
        $("#form").attr("action", "__URL__/sku_real_inventory/p/1");
        $("#form").submit();
    });

</script>






